var comment = {
	appPath: '',
	commentId: '',
	isVerifyCode: 0,
	init:function(path, cid, verify) {
		this.appPath = path;
		this.commentId = cid;
		this.isVerifyCode = verify ? verify : 0;
	},
	onSubmit:function() {
		var owner = this;
		var content = $('#commentContent').val();
		var direction = $('#contentDirection').val();
		if(content == ''){
			alert('请输入您想说的话哦！');
			return false;
		}
		if(this.isVerifyCode){
			var code = $('#verifyText').val() == '' ? $('#verifyTextReplay').val() : $('#verifyText').val();
			var res = $.ajax({
				url: ''+owner.appPath+'index.php?m=pay&c=deposit&a=public_checkcode&code='+code,
				async: false
			}).responseText;
		} else {
			var res = 1;
		}
		if(res != 1) {
			alert('验证码错误');
			return false;
		}
		var data = {code:code, content:content, direction:direction};
		$.ajax({
			type: 'POST',
			url: ''+owner.appPath+'index.php?m=comment&c=index&a=post&format=json&commentid='+owner.commentId+'',
			dataType: 'json',
			data: data,
			success: function(json){
				if(json.status == 1){
					alert('发布成功！');
					$('#commentContent').val('');
					owner.getList(owner.commentId);
				} else {
					alert(json.msg);
				}
			}
		});
	},
	getList:function(commentid) {
		$.get(''+this.appPath+'index.php?m=comment&c=index&a=init&format=json&commentid='+commentid+'&iframe=1', function(data){
			$('#commentList').html(data);
		}, 'html');
	},
	bulidReplay:function(id, commentid) {
		var _html = '<form action="'+this.appPath+'index.php?m=comment&c=index&a=post&commentid='+commentid+'&id='+id+'">';
			_html += '<textarea name="content"></textarea>';
		if(this.isVerifyCode){
			_html += '<label>验证码：<input id="verifyTextReplay" type="text" name="code" onfocus="var offset = $(this).offset();$(\'#verifyCode\').css({\'left\': +offset.left-8, \'top\': +offset.top-$(\'#verifyCode\').height()});$(\'#verifyCode\').show();$(\'#verifyText\').data(\'hide\', 1)" onblur=\'$("#verifyText").data("hide", 0);setTimeout("hideCode();", 3000)\' /></label>';
		}
			_html += '<div><input type="button" value="发布" /></div>';
			_html += '</form>';
		$('#replyBox-'+id).html(_html).toggle();
	}
};

function hideCode() {
	if($('#verifyText').data('hide') == 0) {
		$('#verifyCode').hide();
	}
}
